<template>
  <div>
    <v-title></v-title>
    <ul class="car">
      <li v-for="item in carList" :key="item.id">{{ item.goodsname }}</li>
    </ul>
  </div>
</template>
  
  <script>
import { cartlist } from "../request/api.js";
export default {
  data() {
    return {
      carList: []
    };
  },
  methods: {
    getCarList() {
      //获取登录完成后，存储的用户的uid
      let uid = JSON.parse(localStorage.getItem("userinfo") || "{}").uid;
      cartlist({ uid })
        .then(res => {
          console.log(res);
          if(res.data.code == 200){
            this.carList = res.data.list
          }else{
            // alert(res.data.msg)
          }
        })
        .catch(err => {
          console.log(err);
        });
    }
  },
  mounted() {
    //请求购物车数据
    this.getCarList();
  }
};
</script>
  
  <style scoped>
  .car li{
    border: 1px solid #ccc;
    margin: 10px 30px;
    padding: .2rem;
    color: orange;
  }
</style>